//
// Created by 123 on 2022/11/7.
//

#ifndef CPP_PROJECT_PILES_H
#define CPP_PROJECT_PILES_H
#include "card.h"
#include "game_exception.h"
#include <vector>
#include "constant.h"
#include "game.h"

class Pile{ //8  84  16
private:
    Pile(const Pile&p)=delete;
    Pile&operator=(const Pile&p)=delete;
protected:
    vector<Card*> cards;
public:
//    unsigned int numOfBaseBuildings;
//    unsigned int numOfOrdinaryBuildings;
//    unsigned int numOfLandmarkBuildings;
    Pile() {}
    void addACard(const Card& card);
    virtual void deleteACard(const Card& card);
    class iterator : public vector<Card*>::iterator {
    public:
        iterator(typename vector<Card*>::iterator it):
                vector<Card*>::iterator(it) {}
    };
    iterator begin() {return iterator(cards.begin());}
    iterator end() {return iterator(cards.end());}
};

class BaseBuildings : public Pile{//起始基础建筑
public:
    BaseBuildings();
};

class LandmarkBuildings : public Pile {//常规卡牌
public:
    static unsigned int numOfLandmarkBuildings;
    LandmarkBuildings();
    const Card & getCard(size_t i) const {  //提供获取卡牌的接口
        if(i>numOfLandmarkBuildings) throw GameException("Wrong parameter: number of card not exist.");
        return *cards[i];
    }
    void deleteACard(const Card& card);
    void printAllCards(ostream& o=std::cout);
};

class OrdinaryBuildings : public Pile {//地标建筑
public:
    static unsigned int numOfOrdinaryBuildings;
    OrdinaryBuildings();
    const Card & getCard(size_t i) const {  //提供获取卡牌的接口
        if(i>numOfOrdinaryBuildings) throw GameException("Wrong parameter: number of card not exist.");
        return *cards[i];
    }
    void deleteACard(const Card& card);
    void printAllCards(ostream& o=std::cout);
};

inline ostream& operator<<(ostream& o, const vector<Card*> cards) {
    int i = 1;
    for (Card *card : cards) {
        o << i << ") " << *card << "\t";
        if (i % 5 == 0) o << "\n";
        i++;
    }
    return o;
}


#endif //CPP_PROJECT_PILES_H
